﻿using System;
using System.Collections.Generic;
using DeepEarth.Core.Data;
using System.Linq;
using DeepEarth.Map.Core.Clustering;

#if WINDOWS_PHONE
using DeepEarth.Core.Utilities.WP7;
#endif

namespace DeepEarth.Map.Core.Filters
{
    public class ChangeDetector
    {
        public Tuple<List<ClusterViewModel>, List<ClusterViewModel>> Filter(Dictionary<ClusterViewModel, ClusterViewModel> clusteredViewModels, List<ClusterViewModel> existingViewModels)
        {
            Dictionary<ClusterViewModel, ClusterViewModel> existingAsDictionary = existingViewModels.ToDictionary(k => k);
            List<ClusterViewModel> removed;
            List<ClusterViewModel> added;

            added = clusteredViewModels.Keys.Where(v => !existingAsDictionary.ContainsKey(v)).ToList();
            removed = existingViewModels.Where(e => !clusteredViewModels.ContainsKey(e)).ToList();

            return new Tuple<List<ClusterViewModel>, List<ClusterViewModel>>(removed, added);
        }

    }
}
